﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;
using KeRui.Model;
using System.Text;

public partial class Manage_Cms_FieldPlusItem : System.Web.UI.Page
{
    protected KeRui.Model.CmsFieldAttr modelCmsFieldAttrModify = new CmsFieldAttr();
    protected string btnName = "添加";
    protected string valuesModify;
    protected void Page_Load(object sender, EventArgs e)
    {
        //登录
        ManageHelper.CheckAdminLogin();
        //权限
        ManageHelper.CheckAdminPower("system_fieldspluslist");
        KeRui.BLL.CmsFieldAttr bllCmsFieldAttr = new KeRui.BLL.CmsFieldAttr();
        if (PageRequest.GetString("act") == "modify")
        {
            btnName = "修改";
        }
        string action = PageRequest.GetString("action");
        switch (action)
        {
            case "add":
                //权限判断
                ManageHelper.CheckAdminPower("system_fieldspluslistadd");
                string name = PageRequest.GetString("txtname");
                string values = PageRequest.GetString("txtvalue");
                for (int i = 0; i < values.Split(',').Length; i++)
                {
                    KeRui.Model.CmsFieldAttr modelCmsFieldAttr = new CmsFieldAttr();
                    modelCmsFieldAttr.AttributeName = values.Split(',')[i];
                    modelCmsFieldAttr.AttributeValue = (i + 1).ToString();
                    modelCmsFieldAttr.ClassName = name;
                    modelCmsFieldAttr.ParentID = 0;//一层关系，没有父节点
                    bllCmsFieldAttr.Add(modelCmsFieldAttr);
                }
                //日志
                ManageHelper.AddLog("system_fieldspluslistadd", "添加了字段附加属性ClassName：" + name);
                Response.Redirect("FieldPlusList.aspx");
                Response.End();
                break;
            case "modify":
                //权限
                ManageHelper.CheckAdminPower("system_fieldspluslistupdate");
                //读取
                string className = PageRequest.GetString("class");
                //先全部删除
                bllCmsFieldAttr.Delete(className);
                //重新添加
                string name2 = PageRequest.GetString("txtname");
                string values2 = PageRequest.GetString("txtvalue");
                for (int i = 0; i < values2.Split(',').Length; i++)
                {
                    KeRui.Model.CmsFieldAttr modelCmsFieldAttr = new CmsFieldAttr();
                    modelCmsFieldAttr.AttributeName = values2.Split(',')[i];
                    modelCmsFieldAttr.AttributeValue = (i + 1).ToString();
                    modelCmsFieldAttr.ClassName = name2;
                    modelCmsFieldAttr.ParentID = 0;//一层关系，没有父节点
                    bllCmsFieldAttr.Add(modelCmsFieldAttr);
                }
                //日志
                ManageHelper.AddLog("system_fieldspluslistupdate", "修改了字段附加属性，ClassName为：" + name2);
                Response.Redirect("FieldPlusList.aspx");
                Response.End();
                break;
        }
    }
}
